<?php
	require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Benchmark.class.php' );
	Benchmark::getInstance( );
	
	session_start( );
	define( 'MAIN_DIR', dirname( __FILE__ ) . DIRECTORY_SEPARATOR );
	
	require_once( MAIN_DIR . 'include' . DIRECTORY_SEPARATOR . 'base.inc.php' );
	
	if( isset( $_POST['user_name'] ) && $_POST['user_name'] && isset( $_POST['user_password'] ) && $_POST['user_password'] )	{
		$USERS = ( isset( $USERS ) && isset( $USERS[$_POST['user_name']] ) ? $USERS[$_POST['user_name']] : null );
		if( $USERS && isset( $USERS['password'] ) && $USERS['password'] == md5( $_POST['user_password'] ) )	{
			$_SESSION['user'] = $USERS;
			$_SESSION['user']['name'] = $_POST['user_name'];
			$_SESSION['user']['password'] = '';	// Security issue
		}
		else if( !defined( 'LOGIN_ERROR' ) )
			define( 'LOGIN_ERROR', true );
	}
	else if( isset( $_REQUEST['user_logout'] ) )	{
		session_destroy( );
		session_start( );
	}
	
	unset( $USERS );
	
	if( !isset( $_SESSION['user'] ) )
		$_SESSION['user'] = null;
	require_once( SWAT_DIR . 'pages' . DS . 'template.php' );
